package cn.sinjet.myview;

import com.mgroup.wazehelper.R;

import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import cn.sinjet.viewmodel.ViewEvent;
import cn.sinjet.viewmodel.ViewModel;

public class ControlItem extends FrameLayout{
	 private ImageView mBtnView = null;  
	 private TextView mTextView = null;
	 boolean enable = false;
	public ControlItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		 LayoutInflater.from(context).inflate(R.layout.view_control_item, this, true);
	     mBtnView = (ImageView)findViewById(R.id.control_item_icon);  
	     mTextView = (TextView)findViewById(R.id.control_item_text);
	     ControlItem.this.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				if(enable)
				ViewModel.getIns().onViewEvent(new ViewEvent(ControlItem.this.getId(), ViewEvent.CLICK));
			}
		});
	}

	
    public void setBtnDrawableResource(int resId){
    	mBtnView.setBackgroundResource(resId);
    }
    
    
    public void setItemText(String text,int enable){
    	this.enable = (enable == 1)?true:false;
    	if(this.enable) {
    		ColorStateList csl = (ColorStateList)getResources().getColorStateList(R.color.text_color_control_item);
    		mTextView.setTextColor(csl);
    	}
    	else mTextView.setTextColor(getResources().getColor(R.color.grey_text));
    	mTextView.setText(text);
    }
    
    /*设置文字接口*/  
    public void setText(String str){  
        mTextView.setText(str);  
    } 
    
    
}
